package data;

import java.io.File;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil{
    private static final SessionFactory sessionFactory;
    static{
        try{
        	String ruta=Thread.currentThread().getContextClassLoader().getResource("hibernate.cfg.xml").toString();
        	ruta=ruta.substring(5,ruta.length());
        	File hcfg=new File(ruta);
            sessionFactory=new Configuration().configure(hcfg).buildSessionFactory();
        }
        catch(Throwable ex){
            System.err.println("Error al crear la SessionFactory. "+ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory(){
        return sessionFactory;
    }
}
